package cn.factorybox.item.controller;

import cn.factorybox.common.entity.Result;
import cn.factorybox.item.annotation.ControllerLogAnnotation;
import cn.factorybox.item.service.RoomService;
import cn.factorybox.model.entity.Room;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-09-11 11:30
 */

@Api(tags = "工厂房间管理")
@RestController
public class RoomController {

    @Autowired
    private RoomService roomService;

    @ControllerLogAnnotation(moduleName = "工厂房间管理", functionName = "新建房间")
    @ApiOperation(value = "新建房间", notes = "新建房间")
    @PostMapping("/room")
    public Result saveRoom(HttpServletRequest request, @RequestBody Room room) throws Exception {
        roomService.saveRoom(request,room);
        return Result.ok("保存房间成功");
    }

    @ControllerLogAnnotation(moduleName = "工厂房间管理", functionName = "修改房间信息")
    @ApiOperation(value = "修改房间信息", notes = "修改房间信息")
    @PutMapping("/room")
    public Result updateRoom(@RequestBody  Room room) {
        roomService.updateRoom(room);
        return Result.ok("修改房间成功");
    }

    @ControllerLogAnnotation(moduleName = "工厂房间管理", functionName = "删除房间信息")
    @ApiOperation(value = "删除房间信息", notes = "删除房间信息")
    @DeleteMapping("/room")
    public Result deleteRoom(@RequestParam("id") String id) {
        roomService.deleteRoom(id);
        return Result.ok("删除房间成功");
    }

    @ControllerLogAnnotation(moduleName = "工厂房间管理", functionName = "获取房间信息 - 简短版")
    @ApiOperation(value = "获取房间信息 - 简短版", notes = "获取房间信息 - 简短版")
    @GetMapping("/room/shortlist")
    public Result selectShortList(HttpServletRequest request) throws Exception {
        List<Room> roomList= roomService.selectShortList(request);
        return new Result(roomList,"获取房间列表成功");
    }

    @ControllerLogAnnotation(moduleName = "工厂房间管理", functionName = "获取房间信息 - 正常版")
    @ApiOperation(value = "获取房间信息 - 正常版", notes = "获取房间信息 - 正常版")
    @GetMapping("/room/normalList")
    public Result selectNormalList(HttpServletRequest request) throws Exception {
        List<Room> roomList= roomService.selectNormalList(request);
        return new Result(roomList,"获取房间列表成功");
    }

    @ControllerLogAnnotation(moduleName = "工厂房间管理", functionName = "根据编号number获取单个房间预览数据")
    @ApiOperation(value = "根据编号number获取单个房间预览数据", notes = "根据编号number获取单个房间预览数据")
    @GetMapping("/room/single")
    public Result getSingleRoom(HttpServletRequest request,@RequestParam("number") String number) throws Exception {
        return new Result(roomService.getSingleRoom(request,Integer.parseInt(number)),"数据获取成功");
    }

    @ApiOperation(value = "获取房间列表", notes = "获取房间列表")
    @GetMapping("/room/list")
    public Result selectList(@RequestParam Map<String,Object> map) {
        Map<String,Object> data = roomService.selectList(map);
        return Result.ok(data,"获取房间列表成功");
    }
}
